<?php
namespace app\admin\service;

use app\admin\logic\UserLogic;
use app\admin\servlet\LoginServlet;

class LoginService extends BaseService
{
	private $servlet = null;

	private $user = null;
	
	public function __construct()
	{
		parent::__construct();
		
		$this->servlet = new LoginServlet();

		$this->user = new UserLogic();
		
	}

	//登录验证
	public function login($data = [])
	{
		//获取user
		$user = $this->user->getUser($data);

		//验证user
        if ( $this->servlet->checkUser($user, $data['password']) === false )
        {
            $this->error = $this->servlet->getError();

            return false;
        }

		//保存登录信息
        $this->servlet->saveLogin($user);
		
		return true;
	}
}